package com.tasks.server;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.apache.log4j.*;

public final class DateTime {
	
	static Logger logger = Logger.getLogger(Column.class);
		
	private GregorianCalendar dateTime;
	
	public DateTime() 
	{
		dateTime = new GregorianCalendar();
	}
	
	public DateTime(String value) 
	{
        try 
        {
        	SimpleDateFormat df = Server.df;
			Date date = df.parse(value);
			dateTime = new GregorianCalendar();
			dateTime.setLenient(false);
			dateTime.setTime(date);
		} 
        catch (ParseException e) 
        {
			new ServerException(this, "Date Parse Exception", e);
		}
	}
	
	public String toString() 
	{
		try 
		{
            return Server.df.format(dateTime.getTime()) + (dateTime.get(Calendar.AM_PM) == Calendar.AM ? " AM" : " PM");
		}
		catch (Exception e) 
		{
			new ServerException(this, "toString",e.toString());
			return null;
		} 
	}
}
